package com.etoak.controller;

import com.etoak.common.utils.uuid.IdUtils;
import com.etoak.common.vo.ResultVO;
import com.etoak.entity.LabelCategory;
import com.etoak.service.LabelCategoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hnb
 * @version 1.0
 * @Description:
 * @date 2022/5/11 下午2:58
 */
@RestController
@RequestMapping("/goertek/labelCategory")
public class LabelCategoryController extends BaseController {

    @Autowired
    LabelCategoryService labelCategroyService;


    /**
     * 添加标签分类
     * @param labelCategory
     * @return
     */
    @PostMapping("/add")
    public ResultVO add(@RequestBody LabelCategory labelCategory) {
        labelCategory.setId(IdUtils.simpleUUID());
        int i = labelCategroyService.add(labelCategory);
        if (i != 0) {
            return ResultVO.success(true);
        }
        return ResultVO.error(false);
    }
    @PostMapping("/update")
    public ResultVO update(@RequestBody LabelCategory labelCategory){
        int i=labelCategroyService.update(labelCategory);
        if (i != 0) {
            return ResultVO.success(true);
        }
        return ResultVO.error(false);
    }
    @GetMapping("/query")
    public ResultVO query(LabelCategory labelCategory){
        LabelCategory lab = labelCategroyService.query(labelCategory);
        return ResultVO.success(lab);
    }
    /**
     * 查询标签分类列表
     * @param lableCategory
     * @return
     */
    @GetMapping("/queryList")
    public ResultVO queryList(LabelCategory lableCategory){
        List<LabelCategory> list = labelCategroyService.queryList(lableCategory);
        return ResultVO.success(list);
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids){
        return toAjax(labelCategroyService.delete(ids));
    }

    /**
     * 逻辑删除
     * @param ids
     * @return
     */
    @ResponseBody
    @GetMapping("/delete/{ids}")
    public AjaxResult remove2(@PathVariable String[] ids){
        int i = 0;
        for(String id : ids){
            LabelCategory labelCategory = new LabelCategory();
            labelCategory.setId(id);
            LabelCategory query = labelCategroyService.query(labelCategory);
            query.setDelStatus("1");
            labelCategroyService.update(query);
            i++;
        }
        return AjaxResult.success("已删除"+ i +"条记录",200);
    }

}
